<?php

namespace App\Models;

// use Illuminate\Database\Eloquent\Model;
use App\Models\BaseModel;

class OrderDetail extends BaseModel
{

    public $timestamps = false;

    protected $appends = ['order_id', 'goods_id', 'sku_id', 'goods_name', 'num'];

    protected $fillable = ['order_id', 'goods_id', 'sku_id', 'goods_name', 'num'];

    protected $with = ['goods'];

    protected $casts = [
        'created_at'=>"Y-m-d H:i:s",
        'updated_at'=>"Y-m-d H:i:s",
    ];

    /**
     * 商品信息
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function goods()
    {
        return $this->hasOne(Goods::class, 'id', 'goods_id');
    }

    /**
     * 兑换信息
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    // public function exchange()
    // {
    //     return $this->hasOne(GoodsExchange::class, 'goods_id', 'goods_id');
    // }

    public function getOrderIDAttribute()
    {
        return $this->attributes['order_id'];
    }

    public function getGoodsIdAttribute()
    {
        return $this->attributes['goods_id'];
    }

    public function getSkuIdAttribute()
    {
        return $this->attributes['sku_id'];
    }

    public function getGoodsNameAttribute()
    {
        return $this->attributes['goods_name'];
    }

    public function getNumAttribute()
    {
        return $this->attributes['num'];
    }

    // public function getScoreAttribute()
    // {
    //     return $this->attributes['score'];
    // }

}
